//
//  RecommendKeyView.swift
//  MyTest
//
//  Created by guanzhongwang on 2021/5/16.
//

import UIKit

class SearchHotKeyView: UIView {

    init(items:Array<NewsSearchTextModel>) {
        super.init(frame: .zero)
        var temp:UIView?
        for i in 0..<items.count {
            let key = HotKeyView(item: items[i], index: i)
            addSubview(key)
            key.snp.makeConstraints({
                if temp == nil {
                    $0.top.equalTo(0)
                }else{
                    $0.top.equalTo((temp?.snp.bottom)!).offset(15)
                }
                $0.left.equalTo(0)
                $0.width.equalToSuperview()
            })
            temp = key
        }
        let moreButton = UIButton(type: .custom)
        moreButton.backgroundColor = Separator_COLOR
        moreButton.layer.cornerRadius = 5
        moreButton.font = Font_Size_12
        moreButton.setTitle("查看更多", for: .normal)
        moreButton.setTitleColor(B000_COLOR, for: .normal)
        addSubview(moreButton)
        moreButton.snp.makeConstraints({
            $0.top.equalTo((temp?.snp.bottom)!).offset(15)
            $0.left.equalTo(15)
            $0.height.equalTo(40).priority(.high)
            $0.bottom.right.equalToSuperview().inset(15)
        })
    }
    
    required init?(coder: NSCoder) {
        fatalError()
    }

}
class HotKeyView: UIView {
    init(item:NewsSearchTextModel,index:Int) {
        super.init(frame: .zero)
        let num = UILabel()
        num.font = Font_Size_15
        num.text = "\(index+1)"
        num.textColor = index>2 ? B999_TITLE_COLOR:RED_COLOR
        addSubview(num)
        num.snp.makeConstraints({
            $0.left.equalTo(15)
            $0.top.bottom.equalTo(0)
        })
        let label = UILabel()
        addSubview(label)
        label.textColor = B000_COLOR
        label.font = Font_Size_15
        label.text = "\(item.key)大叔大婶多暗示大声道爱戴暗示大神大大神大声道阿萨德暗示大神大声道暗示阿萨德暗示的"
        label.snp.makeConstraints({
            $0.centerY.equalTo(num)
            $0.left.equalTo(35)
            $0.right.lessThanOrEqualToSuperview().inset(50)
        })
        let icon = UIImageView(image: UIImage(named: "hotkey")?.withRenderingMode(.alwaysTemplate))
        icon.isHidden = !item.isHot
        icon.tintColor = RED_COLOR
        addSubview(icon)
        icon.snp.makeConstraints({
            $0.width.height.equalTo(15)
            $0.centerY.equalTo(num)
            $0.left.equalTo(label.snp.right).offset(-3)
        })
        
        let arrow = UIImageView()
        let image = UIImage(named: "arrowright")?.withRenderingMode(UIImage.RenderingMode.alwaysTemplate)
        arrow.tintColor = B999_TITLE_COLOR
        arrow.image = image
        arrow.tintColor = .lightGray
        addSubview(arrow)
        arrow.snp.makeConstraints({
            $0.centerY.equalTo(num)
            $0.right.equalToSuperview().inset(15)
        })
        
        
    }
    required init?(coder: NSCoder) {
        fatalError()
    }
}
